home *** CD-ROM | disk | FTP | other *** search
- # include "defs.h"
-
- char *Usage =
- "Usage: Makemake [-p] [name=value…] [-i dir]… { -t target sources… }…\n";
-
- char *progname = "Makemake";
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- int i; /* Loop counter */
- int t = 0; /* Counts targets ("-t" arguments) */
- int oops = 0; /* Counts errors in arguments */
- char *sfx; /* Pointer to filename suffix */
- extern char *obj ();
- extern char *getmacro ();
- extern char *strchr ();
- extern char *strrchr ();
-
-
- progname = argv[0];
-
- /*
- * For each command line argument
- */
- for (i = 1; i < argc; i++)
- {
- /*
- * Flags begin with a dash
- */
- if (argv[i][0] == '-') switch (argv[i][1])
- {
- case 'I': /* Include directory */
- case 'i': /* Include directory */
- i++;
- if (i < argc)
- {
- add_dir (argv[i], adirlist);
- add_dir (argv[i], cdirlist);
- add_dir (argv[i], pdirlist);
- }
- break;
- case 'T': /* Target */
- case 't': /* Target */
- t++; /* Count it */
- i++;
- if (t == TARGETMAX)
- goof ("Too many targets (max %d).\n", TARGETMAX);
- else
- targets[t-1] = argv[i];
- break;
- case 'P':
- case 'p':
- verbose = TRUE;
- progress ("Makemake 1.1, by Rick Holzgrafe\n");
- break;
- default:
- goof ("Unrecognized option \"%s\"\n", argv[i]);
- oops++;
- break;
- } /* End if-switch */
-
- else if (strchr (argv[i], '=') != NULL) /* It's a macro */
- setmacro (argv[i]); /* If it has an '=' */
-
- else /* A source file name */
- {
- if (t == 0)
- {
- goof ("A target must be listed before its sources or libraries.\n");
- oops++;
- }
- else
- {
- /*
- * Check the filename suffix.
- * No suffix means a simple dependency;
- * .o is a library (and therefore a dependency)
- * but not a source;
- * any other suffix is a source which produces an object,
- * which in turn is a dependency.
- */
- sfx = strrchr (argv[i], '.');
- if (strcmp (sfx, ".c") == 0
- || strcmp (sfx, ".p") == 0
- || strcmp (sfx, ".a") == 0)
- {
- add_source (argv[i]);
- add_object (t - 1, obj (argv[i]));
- }
- else if (strcmp (sfx, ".o") == 0)
- add_lib (t - 1, argv[i]);
- else if (strcmp (sfx, ".r") == 0)
- {
- add_res (t - 1, argv[i]);
- add_dot_r (argv[i]);
- }
- else
- add_depend (t - 1, argv[i]);
- }
- }
- } /* End for loop */
-
- if (t == 0) /* No targets given */
- oops++;
-
- /*
- * If errors were found in the command line, complain
- * usefully and exit.
- */
- if (oops > 0)
- {
- usage ();
- exit (EXIT_OPT);
- }
-
- /*
- * Add default include dirs to list.
- */
- add_def_dirs ();
-
- /*
- * Set up defaults macros. Since they are defaults,
- * we set them up only if they are not already set
- * (by the command line).
- */
- if (getmacro ("DUP") == NULL)
- smacro ("DUP", "Duplicate");
- if (getmacro ("DUPOPTS") == NULL)
- smacro ("DUPOPTS", "-y");
- if (getmacro ("COUNT") == NULL)
- smacro ("COUNT", "Count");
- if (getmacro ("COUNTOPTS") == NULL)
- smacro ("COUNTOPTS", "");
- if (getmacro ("CTAGS") == NULL)
- smacro ("CTAGS", "Ctags");
- if (getmacro ("CTAGSOPTS") == NULL)
- smacro ("CTAGSOPTS", "-p -update");
- if (getmacro ("DELETE") == NULL)
- smacro ("DELETE", "Delete");
- if (getmacro ("DELETEOPTS") == NULL)
- smacro ("DELETEOPTS", "-y");
- if (getmacro ("FILES") == NULL)
- smacro ("FILES", "Files");
- if (getmacro ("FILESOPTS") == NULL)
- smacro ("FILESOPTS", "-l");
- if (getmacro ("LINK") == NULL)
- smacro ("LINK", "Link");
- if (getmacro ("LINKOPTS") == NULL)
- smacro ("LINKOPTS", "-t 'MPST' -c 'MPS '");
- if (getmacro ("LINKTEMP") == NULL)
- smacro ("LINKTEMP", "link.out");
- if (getmacro ("MAKEFILE") == NULL)
- smacro ("MAKEFILE", "Makefile");
- if (getmacro ("POST") == NULL)
- smacro ("POST", "echo");
- if (getmacro ("POSTOPTS") == NULL)
- smacro ("POSTOPTS", "'Build of'");
- if (getmacro ("POSTARGS") == NULL)
- smacro ("POSTARGS", "'is complete.'");
- if (getmacro ("PRINT") == NULL)
- smacro ("PRINT", "Print");
- if (getmacro ("PRINTOPTS") == NULL)
- smacro ("PRINTOPTS", "");
- if (getmacro ("RENAME") == NULL)
- smacro ("RENAME", "Rename");
- if (getmacro ("RENAMEOPTS") == NULL)
- smacro ("RENAMEOPTS", "-y");
- if (getmacro ("REZ") == NULL)
- smacro ("REZ", "Rez");
- if (getmacro ("REZOPTS") == NULL)
- smacro ("REZOPTS", "-o");
-
- /*
- * All set -- build that makefile!
- */
- makemake (argc, argv);
- exit (EXIT_OK);
- }
-
- /*
- * Add a filename to the list of source files,
- * but only if it's not already there.
- */
- add_source (file)
- char *file;
- {
- int i;
-
- for (i = 0; i < SOURCEMAX && sources[i] != NULL; i++)
- if (strcmp (file, sources[i]) == 0)
- return; /* Got it already */
-
- if (i == SOURCEMAX)
- goof ("Too many source files (max %d).\n", SOURCEMAX);
- else
- sources[i] = file;
- }
-
- /*
- * Add a filename to the list of local C include files,
- * but only if it's not already there.
- * These must be copied to permanent storage.
- */
- add_dot_h (file)
- char *file;
- {
- int i;
- extern char *malloc ();
-
- for (i = 0; i < DOTHMAX && dot_h[i] != NULL; i++)
- if (strcmp (file, dot_h[i]) == 0)
- return; /* Got it already */
-
- if (i == DOTHMAX)
- goof ("Too many local include files (max %d).\n",
- DOTHMAX);
- else
- {
- dot_h[i] = malloc ((unsigned) strlen (file) + 1);
- if (dot_h[i] == NULL)
- nomemory ();
- strcpy (dot_h[i], file);
- }
- }
-
- /*
- * Add a filename to the list of local Rez files,
- * but only if it's not already there.
- */
- add_dot_r (file)
- char *file;
- {
- int i;
-
- for (i = 0; i < DOTHMAX && dot_r[i] != NULL; i++)
- if (strcmp (file, dot_r[i]) == 0)
- return; /* Got it already */
-
- if (i == DOTHMAX)
- goof ("Too many local Rez files (max %d).\n",
- DOTHMAX);
- else
- dot_r[i] = file;
- }
-
- /*
- * Add a directory to a list of include directories.
- */
- add_dir (dir, list)
- char *dir;
- char *list[];
- {
- int i;
-
- for (i = 0; i < DIRMAX && list[i] != NULL; i++)
- ;
- if (i == DIRMAX)
- goof ("Too many include directories (max %d).\n",
- DIRMAX);
- else
- list[i] = dir;
- }
-
- /*
- * Add a filename to the list of object files for the given target.
- * These must be copied to permanent storage.
- */
- add_object (t, file)
- int t; /* Index of the target */
- char *file; /* Object file name */
- {
- int i;
- extern char *malloc ();
-
- for (i = 0; i < SOURCEMAX && objects[t][i] != NULL; i++)
- ;
- if (i == SOURCEMAX)
- goof ("Too many object files for \"%s\" (max %d).\n",
- targets[t], SOURCEMAX);
- else
- {
- objects[t][i] = malloc ((unsigned) strlen (file) + 1);
- if (objects[t][i] == NULL)
- nomemory ();
- strcpy (objects[t][i], file);
- }
- }
-
- /*
- * Add a library to the list of library files for the given target.
- * These must be copied to permanent storage.
- */
- add_lib (t, file)
- int t; /* Index of the target */
- char *file; /* Library file name */
- {
- int i;
- extern char *malloc ();
-
- for (i = 0; i < LIBMAX && liblist[t][i] != NULL; i++)
- ;
- if (i == LIBMAX)
- goof ("Too many libraries for \"%s\" (max %d).\n",
- targets[t], LIBMAX);
- else
- {
- liblist[t][i] = malloc ((unsigned) strlen (file) + 1);
- if (liblist[t][i] == NULL)
- nomemory ();
- strcpy (liblist[t][i], file);
- }
- }
-
- /*
- * Add a filename to the list of "other dependencies" for the given
- * target. These must be copied to permanent storage.
- */
- add_depend (t, file)
- int t; /* Index of the target */
- char *file; /* File name */
- {
- int i;
- extern char *malloc ();
-
- for (i = 0; i < DEPENDMAX && deplist[t][i] != NULL; i++)
- ;
- if (i == DEPENDMAX)
- goof ("Too many extra dependencies for \"%s\" (max %d).\n",
- targets[t], DEPENDMAX);
- else
- {
- deplist[t][i] = malloc ((unsigned) strlen (file) + 1);
- if (deplist[t][i] == NULL)
- nomemory ();
- strcpy (deplist[t][i], file);
- }
- }
-
- /*
- * Add a filename to the list of resource sources for the given
- * target. These must be copied to permanent storage.
- */
- add_res (t, file)
- int t; /* Index of the target */
- char *file; /* File name */
- {
- int i;
- extern char *malloc ();
-
- for (i = 0; i < RESMAX && reslist[t][i] != NULL; i++)
- ;
- if (i == RESMAX)
- goof ("Too many resource dependencies for \"%s\" (max %d).\n",
- targets[t], RESMAX);
- else
- {
- reslist[t][i] = malloc ((unsigned) strlen (file) + 1);
- if (reslist[t][i] == NULL)
- nomemory ();
- strcpy (reslist[t][i], file);
- }
- }
-
- /*
- * Look in the environment for "AIncludes", "CIncludes", "PInterfaces",
- * and "RIncludes", each of which if present should be
- * a comma-separated list of pathnames. Add each pathname to the list
- * of include directories.
- */
- add_def_dirs ()
- {
- int i;
- char c;
- char *s, *t;
- static char **lists[] = { adirlist, cdirlist, pdirlist, rdirlist };
- static char *names[] = { "AIncludes", "CIncludes", "PInterfaces", "RIncludes" };
- extern char *getenv ();
-
- for (i = 0; i < 4; i++)
- {
- if ((s = getenv (names[i])) == NULL)
- continue;
-
- while (*s != EOS)
- {
- for (t = s; *t != EOS && *t != ','; t++)
- ;
- c = *t;
- *t = EOS;
- add_dir (s, lists[i]);
- *t = c;
- if (*t != EOS)
- t++;
- s = t;
- }
- }
- }
-
- nomemory ()
- {
- OSgoof ("Out of memory.\n");
- exit (EXIT_RES);
- }
-
- goof (ms, a,b,c,d,e,f,g,h,i,j)
- {
- fprintf (stderr, "### %s - ", progname);
- fprintf (stderr, ms, a,b,c,d,e,f,g,h,i,j);
- }
-
- OSgoof (ms, a,b,c,d,e,f,g,h,i,j)
- {
- char errbuf[256];
-
- goof (ms, a,b,c,d,e,f,g,h,i,j);
- fprintf (stderr, "# %s\n", GetSysErrText (MacOSErr, errbuf));
- }
-
- usage ()
- {
- fprintf (stderr, "# %s", Usage);
- }
-
- progress (ms, a,b,c,d,e,f,g,h,i,j)
- char *ms;
- {
- if (verbose)
- fprintf (stderr, ms, a,b,c,d,e,f,g,h,i,j);
- }